home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 August / MW 8 2003 CD1.iso / Inside Macworld / Product News / gimp-1.2.4.sit / gimp-1.2.4 / plug-ins / perl / examples / webify < prev    next >
Encoding:
Text File  |  2000-05-21  |  1.5 KB  |  51 lines

  1. #!/usr/app/bin/perl
  2.  
  3. eval 'exec /usr/app/bin/perl  -S $0 ${1+"$@"}'
  4.     if 0; # not running under some shell
  5.  
  6. use Gimp;
  7. use Gimp::Fu;
  8.  
  9. #Gimp::set_trace(TRACE_ALL);
  10.  
  11. register "webify",
  12.          "Make an image suitable for the web",
  13.          "This plug-in converts the image to indexed, with some extra options",
  14.          "Marc Lehmann",
  15.          "Marc Lehmann",
  16.          "1.0",
  17.          N_"<Image>/Filters/Web/Webify...",
  18.          "RGB*, GRAY*",
  19.          [
  20.           [PF_BOOL,    "new",        "create a new image?", 1],
  21.           [PF_BOOL,    "transparent",    "make transparent?", 1],
  22.           [PF_COLOUR,    "bg_color",    "the background colour to use for transparency", "white"],
  23.           [PF_SLIDER,    "threshold",    "the threshold to use for background detection", 3, [0, 255, 1]],
  24.           [PF_INT32,    "colors",    "how many colours to use (0 = don't convert to indexed)", 32],
  25.           [PF_BOOL,    "autocrop",    "autocrop at end?", 1],
  26.          ],
  27.          sub {
  28.    my($img,$drawable,$new,$alpha,$bg,$thresh,$colours,$autocrop)=@_;
  29.  
  30.    $img = $img->channel_ops_duplicate if $new;
  31.  
  32.    eval { $img->undo_push_group_start };
  33.  
  34.    $drawable = $img->flatten;
  35.  
  36.    if ($alpha) {
  37.       $drawable->add_alpha;
  38.       $drawable->by_color_select($bg,$thresh,REPLACE,1,0,0,0);
  39.       $drawable->edit_cut if $img->selection_bounds;
  40.    }
  41.    Plugin->autocrop($drawable) if $autocrop;
  42.    $img->convert_indexed (2, 0, $colours, 0, 0, '') if $colours;
  43.  
  44.    eval { $img->undo_push_group_end };
  45.  
  46.    $new ? ($img->clean_all, $img) : ();
  47. };
  48.  
  49. exit main;
  50.  
  51.